package xcmg.device.web.account;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.account.ArrearsStatisticsService;
import xcmg.device.service.vo.account.ArrearsStatisticsParam;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

/**
 * Created by Administrator on 2019/8/27.
 */
@RestController
@RequestMapping("/arrearsStatistics")
@Api("欠款统计入口")
public class ArrearsStatisticsController extends BasicController {

    @Autowired
    private ArrearsStatisticsService arrearsStatisticsService;

    @PostMapping(value = "/servicePersonList")
    @FastMappingInfo(needLogin = true)
    @ApiOperation("获取服务人员欠款统计列表")
    public ActionResult servicePersonList(@RequestBody SearchCommonVO<ArrearsStatisticsParam> condition)throws Exception{
        ArrearsStatisticsParam arrearsStatisticsParam = condition.getFilters();
        if(arrearsStatisticsParam == null){
            arrearsStatisticsParam = new ArrearsStatisticsParam();
        }
        arrearsStatisticsParam.setOrgId(getOrgId());
        condition.setFilters(arrearsStatisticsParam);
        PageCommonVO pageCommonVO = arrearsStatisticsService.servicePersonList(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @PostMapping(value = "/clientList")
    @FastMappingInfo(needLogin = true)
    @ApiOperation("获取客户统计欠款列表")
    public ActionResult clientList(@RequestBody SearchCommonVO<ArrearsStatisticsParam> condition)throws Exception{
        ArrearsStatisticsParam arrearsStatisticsParam = condition.getFilters();
        if(arrearsStatisticsParam == null){
            return actionResult(ErrorCode.IllegalArument);
        }
        arrearsStatisticsParam.setOrgId(getOrgId());
        PageCommonVO pageCommonVO = arrearsStatisticsService.clientList(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @PostMapping(value = "/orderDetailList")
    @FastMappingInfo(needLogin = true)
    @ApiOperation("获取客户订单详情列表")
    public ActionResult orderDetailList(@RequestBody SearchCommonVO<ArrearsStatisticsParam> condition)throws Exception{
        ArrearsStatisticsParam arrearsStatisticsParam = condition.getFilters();
        if(arrearsStatisticsParam == null){
            return actionResult(ErrorCode.IllegalArument);
        }
        arrearsStatisticsParam.setOrgId(getOrgId());
        PageCommonVO pageCommonVO = arrearsStatisticsService.orderDetailList(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }
}
